"use strict";

/*
 * MikoPBX - free phone system for small business
 * Copyright © 2017-2023 Alexey Portnov and Nikolay Beketov
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along with this program.
 * If not, see <https://www.gnu.org/licenses/>.
 */

/* global MediaStreamRecorder, StereoAudioRecorder, PbxApi, sndPlayer */

/**
 * WebKit sound recorder module.
 * @module webkitRecorder
 */
var webkitRecorder = {
  $recordLabel: $('#record-label'),
  $recordButton: $('#start-record-button'),
  $stopButton: $('#stop-record-button'),
  $selectAudioInput: $('#select-audio-button'),
  $audioPlayer: $('#audio-player'),
  audioInputMenu: document.getElementById('audio-input-select'),
  chunks: [],
  mediaRecorder: '',

  /**
   * Initialize the WebKit sound recorder module.
   */
  initialize: function initialize() {
    webkitRecorder.$stopButton.addClass('disabled'); // Event listener for the record button

    webkitRecorder.$recordButton.on('click', function (e) {
      e.preventDefault();
      webkitRecorder.chunks = [];
      var constraints = {
        audio: true
      };

      if (webkitRecorder.audioInputMenu.getElementsByClassName('selected').length > 0) {
        var audioSource = webkitRecorder.audioInputMenu.getElementsByClassName('selected')[0].id;
        constraints = {
          audio: {
            deviceId: audioSource ? {
              exact: audioSource
            } : undefined
          }
        };
      }

      console.log(constraints);
      webkitRecorder.captureUserMedia(constraints, webkitRecorder.cbOnSuccess, webkitRecorder.gotDevices, webkitRecorder.onError);
    }); // Event listener for the stop button

    webkitRecorder.$stopButton.on('click', function (e) {
      e.preventDefault();
      webkitRecorder.mediaRecorder.stop();
    });
    webkitRecorder.$selectAudioInput.dropdown(); // Disable the field if the protocol is not HTTPS or the hostname is not localhost

    if (window.location.protocol !== 'https:' && window.location.hostname !== 'localhost') {
      $('#only-https-field').addClass('disabled');
    } // Disable the field if the user agent is MSIE


    if (window.navigator.userAgent.indexOf('MSIE ') > 0) {
      $('#only-https-field').addClass('disabled');
    }
  },

  /**
   * Capture user media based on media constraints.
   * @param {MediaStreamConstraints} mediaConstraints - The media constraints for capturing user media.
   * @param {Function} successCallback - The success callback function to handle captured media stream.
   * @param {Function} gotDevicesCallBack - The callback function to handle the list of available devices.
   * @param {Function} errorCallback - The error callback function to handle errors during media capture.
   */
  captureUserMedia: function captureUserMedia(mediaConstraints, successCallback, gotDevicesCallBack, errorCallback) {
    navigator.mediaDevices.getUserMedia(mediaConstraints).then(successCallback).then(gotDevicesCallBack)["catch"](errorCallback);
  },

  /**
   * Callback function called when devices are retrieved.
   * @param {MediaDeviceInfo[]} deviceInfos - The array of retrieved device info.
   */
  gotDevices: function gotDevices(deviceInfos) {
    if (webkitRecorder.audioInputMenu.getElementsByTagName('div').length > 0) return;

    for (var i = 0; i !== deviceInfos.length; i += 1) {
      var deviceInfo = deviceInfos[i];
      var option = document.createElement('div');
      option.className = 'item';
      option.id = deviceInfo.deviceId;

      if (deviceInfo.kind === 'audioinput') {
        option.innerHTML = deviceInfo.label || "microphone ".concat(webkitRecorder.audioInputMenu.length + 1);
        webkitRecorder.audioInputMenu.appendChild(option);
      }
    }

    if (webkitRecorder.audioInputMenu.getElementsByTagName('div').length > 0) {
      webkitRecorder.$selectAudioInput.removeClass('disabled');
    }
  },

  /**
   * Callback function called after successfully capturing user media.
   * @param {MediaStream} stream - The captured media stream.
   * @returns {Promise} - The promise to enumerate devices.
   */
  cbOnSuccess: function cbOnSuccess(stream) {
    try {
      webkitRecorder.mediaRecorder = new MediaStreamRecorder(stream);
      webkitRecorder.mediaRecorder.stream = stream;
      webkitRecorder.mediaRecorder.recorderType = StereoAudioRecorder;
      webkitRecorder.mediaRecorder.mimeType = 'audio/wav';
      webkitRecorder.mediaRecorder.audioChannels = 1; // webkitRecorder.mediaRecorder = new MediaRecorder(stream);

      webkitRecorder.mediaRecorder.onstop = webkitRecorder.cbOnStopMediaRecorder;
      webkitRecorder.mediaRecorder.ondataavailable = webkitRecorder.cbOnDataAvailable;
      webkitRecorder.mediaRecorder.start(300000);
      console.log('recorder started');
      webkitRecorder.$recordLabel.addClass('red');
      webkitRecorder.$stopButton.removeClass('disabled');
      webkitRecorder.$recordButton.addClass('disabled');
      return navigator.mediaDevices.enumerateDevices();
    } catch (e) {
      console.error('MediaStreamRecorder is not supported by this browser.\n\n' + 'Try Firefox 29 or later, or Chrome 47 or later, with Enable experimental Web Platform features enabled from chrome://flags.');
      console.error('Exception while creating MediaRecorder:', e);
      webkitRecorder.$recordButton.addClass('disabled');
    }

    return false;
  },

  /**
   * Callback function called when an error occurs.
   * @param {Error} err - The error object.
   */
  cbOnError: function cbOnError(err) {
    console.log("The following error occured: ".concat(err));
  },

  /**
   * Callback function called when media recorder is stopped.
   */
  cbOnStopMediaRecorder: function cbOnStopMediaRecorder() {
    console.log('data available after MediaStreamRecorder.stop() called.');
    soundFileModify.blob = new Blob(webkitRecorder.chunks);
    console.log('recorder stopped');
    var fileURL = URL.createObjectURL(soundFileModify.blob);
    sndPlayer.UpdateSource(fileURL);
    var blobFile = new File([webkitRecorder.chunks[0]], 'blob' + new Date().getTime() + '.wav');
    PbxApi.FilesUploadFile(blobFile, soundFileModify.cbUploadResumable);
    webkitRecorder.$recordLabel.removeClass('red');
    webkitRecorder.$stopButton.addClass('disabled');
    webkitRecorder.$recordButton.removeClass('disabled');
    soundFileModify.$soundFileInput.val('');
  },

  /**
   * Callback function called when data is available.
   * @param {BlobEvent} e - The blob event.
   */
  cbOnDataAvailable: function cbOnDataAvailable(e) {
    webkitRecorder.chunks.push(e);
  }
}; // When the document is ready, initialize the web kit sound recorder

$(document).ready(function () {
  webkitRecorder.initialize();
});
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9Tb3VuZEZpbGVzL3NvdW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lKSA9PiB7XG4gICAgICAgICAgICBlLnByZXZlbnREZWZhdWx0KCk7XG4gICAgICAgICAgICB3ZWJraXRSZWNvcmRlci5jaHVua3MgPSBbXTtcbiAgICAgICAgICAgIGxldCBjb25zdHJhaW50cyA9IHtcbiAgICAgICAgICAgICAgICBhdWRpbzogdHJ1ZSxcbiAgICAgICAgICAgIH07XG4gICAgICAgICAgICBpZiAod2Via2l0UmVjb3JkZXIuYXVkaW9JbnB1dE1lbnUuZ2V0RWxlbWVudHNCeUNsYXNzTmFtZSgnc2VsZWN0ZWQnKS5sZW5ndGggPiAwKSB7XG4gICAgICAgICAgICAgICAgY29uc3QgYXVkaW9Tb3VyY2UgPSB3ZWJraXRSZWNvcmRlci5hdWRpb0lucHV0TWVudS5nZXRFbGVtZW50c0J5Q2xhc3NOYW1lKCdzZWxlY3RlZCcpWzBdLmlkO1xuICAgICAgICAgICAgICAgIGNvbnN0cmFpbnRzID0ge1xuICAgICAgICAgICAgICAgICAgICBhdWRpbzoge2RldmljZUlkOiBhdWRpb1NvdXJjZSA/IHtleGFjdDogYXVkaW9Tb3VyY2V9IDogdW5kZWZpbmVkfSxcbiAgICAgICAgICAgICAgICB9O1xuICAgICAgICAgICAgfVxuICAgICAgICAgICAgY29uc29sZS5sb2coY29uc3RyYWludHMpO1xuICAgICAgICAgICAgd2Via2l0UmVjb3JkZXIuY2FwdHVyZVVzZXJNZWRpYShcbiAgICAgICAgICAgICAgICBjb25zdHJhaW50cyxcbiAgICAgICAgICAgICAgICB3ZWJraXRSZWNvcmRlci5jYk9uU3VjY2VzcyxcbiAgICAgICAgICAgICAgICB3ZWJraXRSZWNvcmRlci5nb3REZXZpY2VzLFxuICAgICAgICAgICAgICAgIHdlYmtpdFJlY29yZGVyLm9uRXJyb3IsXG4gICAgICAgICAgICApO1xuICAgICAgICB9KTtcblxuICAgICAgICAvLyBFdmVudCBsaXN0ZW5lciBmb3IgdGhlIHN0b3AgYnV0dG9uXG4gICAgICAgIHdlYmtpdFJ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